const mongoose = require("mongoose")
const bean = require("../bean/user")
const Model = mongoose.model('user', bean)
const {random} = require("../utils/index")
module.exports = {
  async save(data) {
    let model = new Model(data)
    try {
      await new Promise((resolve, reject) => {
        process.rdb.set(data.username, data.password, e => {
          if (!e) {
            resolve(true)
          } else {
            reject(err)
          }
        })
      })
    } catch (error) {
      console.log(`err \n${error}`)
    }

    return await model.save()
  },
  async get(post) {
    let data = await Model.findOne({username: post.username, password: post.password})
    if (!data) {
      return {type: false, msg: "密码或用户名错误", data: null}
    } else {
      // 生成token
      let token = random()
      // 更新token
      process.rdb.setExP
    }
  }
}

